<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var isSymmetric = function (root) {
        function levelOrder(root) {
          if (!root) return []
          let queue = [root]
          let res = []
          while (queue.length) {
            let len = queue.length
            res.push([])
            for (let i = 0; i < len; i++) {
              let node = queue.shift()
              if (node) {
                res[res.length - 1].push(node.val)
                queue.push(node.left)
                queue.push(node.right)
              } else {
                res[res.length - 1].push(null)
              }
            }
          }
          return res
        }

        let res = levelOrder(root)
        return res.every(item => isPali(item))
        function isPali(arr) {
          let left = 0
          let right = arr.length - 1
          while (left <= right) {
            if (arr[left++] != arr[right--]) return false
          }
          return true
        }
      }
    </script>
  </body>
</html>
